package com.example.meituanservice.controller;

import com.example.meituanservice.Mapper.UserMapper;
import com.example.meituanservice.entity.Result;
import com.example.meituanservice.pojo.User;
import com.example.meituanservice.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.executor.ResultExtractor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("/login")
    public Result Login(@RequestBody User user){
        User user1 = userService.Login(user);
        if(user1==null){
            return Result.error("账号或密码错误");
        }else{
            return Result.success(user1);
        }
    }
    @RequestMapping("/regist")
    public Result Regist(@RequestBody User user){
        System.out.println(user.toString());
        int res = userService.regist(user);
        if(res==0){
            return Result.error("注册失败");
        }else {
            return Result.success(user);
        }
    }
    @GetMapping("/modify")
    public Result Modify(@RequestParam("username")String username,@RequestParam("oldpassword")String oldpassword,@RequestParam("newpassword")String newpassword){
        if(true){
            return Result.success(newpassword);
        }else {
            return Result.error("修改失败");
        }
    }
}
